package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityChatMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CROSS_ACTIVITY_GROUP_CHAT_LIST, desc = "跨服活动聊天列表")
public class CrossActivityGroupChatListCmd extends CrossUnionCommand {
    private int activityId;
    private long userId;
    private int param2 = 0;

    private int groupId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossActivityChatListReqMsg reqMsg = CrossActivityProto.CrossActivityChatListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        if (reqMsg.hasParam2()) {
            param2 = reqMsg.getParam2();
        }
        groupId = reqMsg.getGroupId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        WorldMessageProto.WorldMessageListMsg.Builder msg = ActivityChatMgr.getChatListMsg(activityId, param2,groupId);
        CrossActivityProto.CrossActivityChatListRespMsg.Builder respMsg = CrossActivityProto.CrossActivityChatListRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        if(null != msg) {
            respMsg.setDataList(msg);
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_ACTIVITY_CHAT_LIST_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
